package com.gusto.engine.spring.parsers;

import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;
import com.gusto.engine.semsim.measures.impl.ZipCodeSimilarity;

public class ParserZipCodeSimilarity extends AbstractBeanDefinitionParser {
	
	protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
		BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.rootBeanDefinition(ZipCodeSimilarity.class);
		
		if (element.hasAttribute("level1")) {
			String level1 = element.getAttribute("level1");
			beanDefinitionBuilder.addPropertyValue("level1", level1);
		}
		if (element.hasAttribute("level2")) {
			String level2 = element.getAttribute("level2");
			beanDefinitionBuilder.addPropertyValue("level2", level2);
		}
		if (element.hasAttribute("level3")) {
			String level3 = element.getAttribute("level3");
			beanDefinitionBuilder.addPropertyValue("level3", level3);
		}
		if (element.hasAttribute("level4")) {
			String level4 = element.getAttribute("level4");
			beanDefinitionBuilder.addPropertyValue("level4", level4);
		}
		if (element.hasAttribute("level5")) {
			String level5 = element.getAttribute("level5");
			beanDefinitionBuilder.addPropertyValue("level5", level5);
		}
		
		return beanDefinitionBuilder.getBeanDefinition();
	}
}
